package com.liruo.learn.spring.security.auth.service;

import com.liruo.learn.spring.security.auth.AuthenticUser;
import com.liruo.learn.spring.security.user.User;
import lombok.Setter;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @Author:liruo
 * @Date:2023-05-18-17:42:52
 * @Desc
 */
@Service
public class AuthenticationUserDetailsService implements UserDetailsService {
    @Setter
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if(username.equals("lym")){
            return new AuthenticUser(new User(1L,"lym", passwordEncoder.encode("123456"), "2372221537@qq.com", "12345678901"));
        }
        throw new UsernameNotFoundException("has not the user " + username);
    }
}
